
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Java Executor · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../category/redis.html" />
    
    
    <link rel="prev" href="Java之Future.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Mysql/经典数据库设计案例.html">
            
                <a href="../Mysql/经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Mysql/Mysql事务与锁.html">
            
                <a href="../Mysql/Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Mysql/mysql数据类型.html">
            
                <a href="../Mysql/mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="Java并发.html">
            
                <a href="Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="Java并发.html">
            
                <a href="Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="Java并发.html">
            
                <a href="Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="Java之Lock.html">
            
                <a href="Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="Java之Lock.html">
            
                <a href="Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="Java之Future.html">
            
                <a href="Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="Java之Future.html">
            
                <a href="Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="Java之Future.html">
            
                <a href="Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="Java之Future.html">
            
                <a href="Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.10" data-path="Java之Executor.html">
            
                <a href="Java之Executor.html">
            
                    
                    Java Executor
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Java Executor</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="java-executor">Java Executor</h1>
<h2 id="&#x539F;&#x5219;">&#x539F;&#x5219;</h2>
<ul>
<li><code>new Thread()</code>&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x7684;&#xFF0C;&#x5E94;&#x7528;&#x5C42;&#x4E0D;&#x5E94;&#x81EA;&#x884C;&#x521B;&#x5EFA;&#x539F;&#x751F;&#x7EBF;&#x7A0B;&#xFF1B;&#x4F7F;&#x7528;&#x7EBF;&#x7A0B;&#x6C60;&#x6548;&#x7387;&#x66F4;&#x9AD8;&#x3001;API&#x66F4;&#x65B9;&#x4FBF;&#x64CD;&#x4F5C;&#x3001;&#x66F4;&#x5B89;&#x5168;&#x53EF;&#x9760;</li>
<li>ForkJoinPool&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x4E0D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;commonPool&#xFF0C;&#x5E94;&#x81EA;&#x5B9A;&#x4E49;&#x5E76;&#x6307;&#x5B9A;&#x6700;&#x5927;&#x7EBF;&#x7A0B;&#x6570;</li>
</ul>
<h2 id="&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x72B6;&#x6001;">&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x72B6;&#x6001;</h2>
<p><img src="assets/1583988216194.png" alt="1583988216194"></p>
<ul>
<li>&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;&#x9ED8;&#x8BA4;Running&#x72B6;&#x6001;</li>
<li>&#x8C03;&#x7528;shutdown()&#x63A5;&#x53E3;&#xFF0C;&#x7EBF;&#x7A0B;&#x6C60;&#x4E0D;&#x80FD;&#x63A5;&#x6536;&#x65B0;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x4F46;&#x53EF;&#x4EE5;&#x7EE7;&#x7EED;&#x5904;&#x7406;&#x5DF2;&#x6DFB;&#x52A0;&#x7684;&#x4EFB;&#x52A1;</li>
<li>&#x8C03;&#x7528;shutdownNow()&#x63A5;&#x53E3;&#xFF0C;&#x53D8;&#x4E3A;STOP&#x72B6;&#x6001;&#xFF0C;&#x4E0D;&#x6536;&#x65B0;&#x7684;&#xFF0C;&#x4E0D;&#x5904;&#x7406;&#x4E00;&#x5929;&#x5047;&#x7684;</li>
<li>TIDYING&#x4EFB;&#x52A1;&#x8BB0;&#x5F55;&#x6570;&#x4E3A;0</li>
<li><strong>TERMINATED</strong>&#x7EBF;&#x7A0B;&#x6C60;&#x5F7B;&#x5E95;&#x7EC8;&#x6B62;</li>
</ul>
<h2 id="executor&#x7684;&#x6269;&#x5C55;&#x63A5;&#x53E3;&#x4E0E;&#x57FA;&#x7840;&#x5B9E;&#x73B0;&#x7C7B;">Executor&#x7684;&#x6269;&#x5C55;&#x63A5;&#x53E3;&#x4E0E;&#x57FA;&#x7840;&#x5B9E;&#x73B0;&#x7C7B;</h2>
<p><img src="assets/1583984617322.png" alt="1583984617322"></p>
<ul>
<li>ExecutorService&#x6269;&#x5C55;&#x4E86;Executor&#x63A5;&#x53E3;&#xFF0C;&#x589E;&#x52A0;&#x4E86;&#x7BA1;&#x7406;&#x751F;&#x547D;&#x5468;&#x671F;&#x7684;&#x65B9;&#x6848;</li>
<li>ScheduledExecutorService</li>
</ul>
<h2 id="threadpoolexecutor">ThreadPoolExecutor</h2>
<p><code>ThreadPoolExecutor</code>&#x63D0;&#x4F9B;&#x4E86;<code>Executor</code>&#x7684;&#x57FA;&#x672C;&#x5B9E;&#x73B0;</p>
<p>&#x521B;&#x5EFA;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-java">ThreadPoolExecutor executorService =(ThreadPoolExecutor)Executors.newCachedThreadPool();

ThreadPoolExecutor executorService1 = (ThreadPoolExecutor)Executors.newFixedThreadPool(<span class="hljs-number">2</span>);
</code></pre>
<p>&#x7EBF;&#x7A0B;&#x6C60;&#x5BB9;&#x91CF;&#x5DE5;&#x4F5C;&#x539F;&#x7406;</p>
<p><img src="assets/1583985347797.png" alt="1583985347797"></p>
<p>&#x6838;&#x5FC3;&#x53C2;&#x6570;</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>corePoolSize</td>
<td>&#x6838;&#x5FC3;&#x6C60;&#x7684;&#x5927;&#x5C0F;</td>
<td>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7EBF;&#x7A0B;&#x6C60;&#x4E2D;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x7EBF;&#x7A0B;&#xFF0C;&#x800C;&#x662F;&#x7B49;&#x5F85;&#x6709;&#x4EFB;&#x52A1;&#x5230;&#x6765;&#x624D;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x53BB;&#x6267;&#x884C;&#x4EFB;&#x52A1;</td>
</tr>
<tr>
<td>maximumPoolSize</td>
<td>&#x6C60;&#x4E2D;&#x5141;&#x8BB8;&#x7684;&#x6700;&#x5927;&#x7EBF;&#x7A0B;&#x6570;</td>
<td></td>
</tr>
<tr>
<td>keepAliveTime</td>
<td>&#x8868;&#x793A;&#x7EBF;&#x7A0B;&#x6CA1;&#x6709;&#x4EFB;&#x52A1;&#x6267;&#x884C;&#x65F6;&#x6700;&#x591A;&#x4FDD;&#x6301;&#x591A;&#x4E45;&#x65F6;&#x95F4;&#x4F1A;&#x7EC8;&#x6B62;</td>
<td>&#x53EA;&#x6709;&#x7EBF;&#x7A0B;&#x6570;&#x5927;&#x4E8E;corePoolSize&#x624D;&#x751F;&#x6548;</td>
</tr>
<tr>
<td>workQueue</td>
<td>&#x6CA1;&#x6709;&#x7A7A;&#x95F2;&#x7EBF;&#x7A0B;&#x5904;&#x7406;&#x7684;&#x4EFB;&#x52A1;&#x961F;&#x5217;</td>
<td></td>
</tr>
<tr>
<td>threadFactory</td>
<td>&#x6267;&#x884C;&#x7A0B;&#x5E8F;&#x521B;&#x5EFA;&#x65B0;&#x7EBF;&#x7A0B;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x7EBF;&#x7A0B;&#x5DE5;&#x5382;</td>
<td></td>
</tr>
<tr>
<td>handler</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="executors&#x5E38;&#x89C1;&#x5EFA;&#x6C60;&#x65B9;&#x5F0F;">Executors&#x5E38;&#x89C1;&#x5EFA;&#x6C60;&#x65B9;&#x5F0F;</h3>
<p><code>Executors</code>&#x7C7B;&#x63D0;&#x4F9B;&#x591A;&#x79CD;&#x5E38;&#x7528;&#x7684;&#x5EFA;&#x6C60;&#x65B9;&#x5F0F;</p>
<h3 id="newfixedthreadpoolint-nthreads">newFixedThreadPool(int nThreads)</h3>
<ul>
<li>nThreads&#x65E2;&#x4E3A;coreSize&#xFF0C;&#x4E5F;&#x662F;maxSize&#xFF1A;&#x89C4;&#x6A21;&#x53D7;&#x9650;&#x4E0E;nThreads</li>
<li>&#x56FA;&#x5B9A;&#x7EBF;&#x7A0B;&#x6570;&#xFF0C;&#x6CA1;&#x6709;&#x8D85;&#x51FA;coreSize&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;keepAliveTime&#x4E5F;&#x4E0D;&#x8D77;&#x4F5C;&#x7528;</li>
<li>&#x6CA1;&#x6709;&#x7EBF;&#x7A0B;&#x5904;&#x7406;&#x7684;&#x4EFB;&#x52A1;&#x8FDB;&#x5165;&#x7B49;&#x5F85;&#x961F;&#x5217;</li>
<li>LinkedBlockingQueue&#x4F5C;&#x4E3A;&#x963B;&#x585E;&#x961F;&#x5217;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ExecutorService <span class="hljs-title">newFixedThreadPool</span><span class="hljs-params">(<span class="hljs-keyword">int</span> nThreads)</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ThreadPoolExecutor(nThreads, nThreads,
                                  <span class="hljs-number">0L</span>, TimeUnit.MILLISECONDS,
                                  <span class="hljs-keyword">new</span> LinkedBlockingQueue&lt;Runnable&gt;());
}
</code></pre>
<h3 id="newcachedthreadpool">newCachedThreadPool()</h3>
<ul>
<li>&#x4E0D;&#x8BBE;&#x7F6E;coreSize&#xFF0C;maxSize&#x53D6;INT&#x6700;&#x5927;&#x503C;&#xFF1A;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x89C4;&#x6A21;&#x4E0D;&#x53D7;&#x9650;</li>
<li>&#x7A7A;&#x95F2;&#x7EBF;&#x7A0B;keepalive&#x65F6;&#x957F;60&#x79D2;&#xFF1A;&#x53EF;&#x7075;&#x6D3B;&#x56DE;&#x6536;&#x7A7A;&#x95F2;&#x7EBF;&#x7A0B;&#xFF0C;&#x65E0;&#x7A7A;&#x95F2;&#x624D;&#x65B0;&#x5EFA;</li>
<li>SynchronousQueue&#x4F5C;&#x4E3A;&#x963B;&#x585E;&#x961F;&#x5217;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ExecutorService <span class="hljs-title">newCachedThreadPool</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ThreadPoolExecutor(<span class="hljs-number">0</span>, Integer.MAX_VALUE,
                                  <span class="hljs-number">60L</span>, TimeUnit.SECONDS,
                                  <span class="hljs-keyword">new</span> SynchronousQueue&lt;Runnable&gt;());
}
</code></pre>
<h3 id="newsinglethreadexecutor"><strong>newSingleThreadExecutor()</strong></h3>
<p>&#x53EA;&#x5141;&#x8BB8;&#x552F;&#x4E00;&#x4E00;&#x6761;&#x5DE5;&#x4F5C;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x4EFB;&#x52A1;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-03-12 12:48:03
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Java之Future.html#forkjointask" class="navigation navigation-prev " aria-label="Previous page: Java Future之ForkJoinTask">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../category/redis.html" class="navigation navigation-next " aria-label="Next page: Redis">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Java Executor","level":"1.4.10","depth":2,"next":{"title":"Redis","level":"1.5","depth":1,"path":"category/redis.md","ref":"category/redis.md","articles":[{"title":"Redis","level":"1.5.1","depth":2,"path":"Redis/Redis.md","ref":"Redis/Redis.md","articles":[]},{"title":"Redis集群","level":"1.5.2","depth":2,"anchor":"#集群","path":"Redis/Redis.md","ref":"Redis/Redis.md#集群","articles":[]},{"title":"Redis消息订阅","level":"1.5.3","depth":2,"anchor":"#消息订阅","path":"Redis/Redis.md","ref":"Redis/Redis.md#消息订阅","articles":[]},{"title":"Redis Lua脚本","level":"1.5.4","depth":2,"anchor":"#lua","path":"Redis/Redis.md","ref":"Redis/Redis.md#lua","articles":[]},{"title":"Redis配置汇总","level":"1.5.5","depth":2,"anchor":"#配置汇总","path":"Redis/Redis.md","ref":"Redis/Redis.md#配置汇总","articles":[]}]},"previous":{"title":"Java Future之ForkJoinTask","level":"1.4.9","depth":2,"anchor":"#forkjointask","path":"Java-Base/Java之Future.md","ref":"Java-Base/Java之Future.md#forkjointask","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"Java-Base/Java之Executor.md","mtime":"2020-03-12T04:48:03.380Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-13T06:50:07.344Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

